"use strict";
module.exports = (app) => {
  const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
  const VideLikes = app.model.define("video_likes", {
    id: {
      type: INTEGER(20).UNSIGNED,
      autoIncrement: true,
      primaryKey: true,
    },
    user_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      references: {
        model: "user",
        key: "id",
      },
      comment: "用户id",
      onUpdate: "restrict", // 更新时操作
      onDelete: "cascade", // 删除时操作
    },
    video_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      references: {
        model: "video",
        key: "id",
      },
      comment: "视频id",
      onUpdate: "restrict", // 更新时操作
      onDelete: "cascade", // 删除时操作
    },
    created_at: DATE,
    updated_at: DATE,
  });
  VideLikes.associate = function (model) {
    VideLikes.hasMany(app.model.Video, {
      foreignKey: "id",
    });
    VideLikes.belongsTo(app.model.User, {
      foreignKey: "user_id",
    });
  };
  return VideLikes;
};
